package edu.wschina.module_c_hanoitower;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;

import edu.wschina.module_c_hanoitower.databinding.ActivityHomeBinding;


public class HomeActivity extends AppCompatActivity {
    private ActivityHomeBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // 在 setContentView 之前初始化 binding
        binding = ActivityHomeBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        binding.nameInput.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }
            @Override
            public void afterTextChanged(Editable editable) {
                if (editable.toString().length() < 6) {
                    binding.nameInput.setError("昵称必须大于等于6位！");
                }

            }
        });

        binding.level1.setOnClickListener(view -> {
            MyApp.getInstance().diskCount=3;
            MyApp.getInstance().should=7;
            binding.level1.setBackgroundResource(R.drawable.bg_selected);
            binding.selectedA.setVisibility(View.VISIBLE);
            binding.level2.setBackgroundResource(R.drawable.bg_unselected);
            binding.selectedB.setVisibility(View.GONE);
        });
        binding.level2.setOnClickListener(view -> {
            MyApp.getInstance().diskCount=4;
            MyApp.getInstance().should=14;
            binding.level2.setBackgroundResource(R.drawable.bg_selected);
            binding.selectedB.setVisibility(View.VISIBLE);
            binding.level1.setBackgroundResource(R.drawable.bg_unselected);
            binding.selectedA.setVisibility(View.GONE);
        });

        binding.startBtn.setOnClickListener(view -> {
            Intent intent = new Intent(this, GameActivity.class);
            startActivity(intent);
            finish();
        });
        /*@description:打开排行榜
        @author aimin 2025-01-07 14:20:36*/
        binding.gotoRank.setOnClickListener(view -> {
            startActivity(new Intent(this, RankActivity.class));
        });
    }
}